{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Evaluate Input Script Parameters\n",
    "* Set Parameters from input script\n",
    "* Evaluate Elementary Process Rates\n",
    "* Evaluate Deposition Parameters\n",
    "* Evaluate Substrate Parameters\n",
    "* more cool stuff"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### import modules"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib notebook\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import importlib\n",
    "from pathlib import Path"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import KMC_Deposition_v3p4p1 as KMC_Dep\n",
    "import KMC_Miscellaneous_v3p4p1 as KMC_Misc\n",
    "import KMC_Analysis_v3p4p1 as KMC_Analysis\n",
    "import KMC_Processes_v3p4p1 as KMC_Proc"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "importlib.reload(KMC_Dep)\n",
    "importlib.reload(KMC_Misc)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Set Parameters"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "Parameters = {}     # Create Parameters Dictionary\n",
    "\n",
    "Parameters['Current_Version'] = 'v3.4.1'   # version of KMC running\n",
    "\n",
    "\n",
    "# Simulation Parameters\n",
    "Parameters['Project_Name'] = 'Density'      # Name for the project save directory.\n",
    "Parameters['Simulation_Name'] = 'R88_Test'          # Name of particular simulation within a project. Can be an empty string, '', because it's DateTime stamped\n",
    "\n",
    "Parameters['Enable_Print_Outs'] = True          # Enable/Disable simulation prinouts.\n",
    "Parameters['Enable_Plots'] = True               # Display final plots at end of simulation. Set to False if running multiple simulations\n",
    "\n",
    "Parameters['Solver_Type'] = 'Binary'            # Type of Solver: 'Linear' O(N^2), 'Binary' O(N log N), 'Set' O(N log N) (currently not wokring)\n",
    "\n",
    "Parameters['Simulation_Type'] = 'Deposition'    # Simulation Type. Choices: 'Deposition', 'Diffusion', 'Density', 'Ising' (future)\n",
    "Parameters['Dimension'] = '3D'                  # Either 2D (1+1) or 3D (2+1). For 2D only Lx is used.\n",
    "\n",
    "Parameters['Number_of_Simulations'] = 1         # Number of back-to-back simulations to perform (fixed parameters). Analysis results will be averaged.\n",
    "\n",
    "\n",
    "\n",
    "# Save Data Parameters - (Note: Data is now saved at each analysis time step)\n",
    "Parameters['Save_All_Events'] = False          # Saves all events in the simulation to output file.\n",
    "Parameters['Save_Lattice'] = False             # Save snapshot of lattice at specified times.\n",
    "Parameters['Save_Surface'] = False             # Save a top down view of surface at specified times.\n",
    "Parameters['Save_Time_Step'] = 0.1             # Time interval to save lattice and statistics data (set to resolution needed for post analysis). Also for Progress Bar update.\n",
    "Parameters['Save_with_Analysis'] = False       # Save data at same time as analysis. This overrides the above time step (though it is still used for progress bar). \n",
    "\n",
    "\n",
    "\n",
    "# On-the-Fly Analysis Parameters - Note: currently only enabled for 3D Deposition simulations\n",
    "Parameters['Coverage'] = True                  # do a coverage analysis\n",
    "Parameters['Island_Analysis'] = False           # do island size distribution analysis\n",
    "Parameters['Structure_Factor'] = False          # do structure factor analysis\n",
    "Parameters['Gaussian_Filter'] = 1.0            # apply gaussian filter to SF analysis. 0 = no filter, > 0 = sigma value\n",
    "\n",
    "Parameters['Analysis_Style'] = 'time'              # choose whether to analyze simulation by time step ('time') or simulation steps ('step')\n",
    "Parameters['Analysis_Time_Spacing'] = 'linear'     # delta t spacing of analysis points. Options: 'linear', 'quad', 'log'. For 'log' this is time of first data point\n",
    "Parameters['Log_Points'] = 100                     # For log spacing option only. This is the number of points per pulse. Set 'Analysis_Delta_Time' to be the first analysis point\n",
    "\n",
    "Parameters['Analysis_Delta_Time'] = 0.1      # time interval for On-the-Fly analysis in seconds. Set 'Analysis_Style' to 'time'\n",
    "Parameters['Analysis_Delta_Step'] = 1e4      # step interval for On-the-Fly analysis. This will result in non-linear time step for analysis points. Set 'Analysis_Style' to 'step'\n",
    "\n",
    "Parameters['On_the_Fly_Save'] = False         # whether to save the on-the-fly results for each simulation. Usually true, unless doing multiple simulations.\n",
    "Parameters['Average_Results'] = False          # average on-the-fly results and save across mulit-simulations. Only used when running multiple simulations.\n",
    "\n",
    "\n",
    "\n",
    "# Substrate Parameters\n",
    "Parameters['Lx'] = 200                   # Substrate size in x direction\n",
    "Parameters['Ly'] = 200                   # Substrate size in y direction (not used in 2D mode)\n",
    "Parameters['depth'] = 5                 # Substrate size in z direction. Give yourself enough layers. (be careful setting this, or errors could occur)\n",
    "\n",
    "Parameters['Substrate_Type'] = 'Islands'           # Substrate Type. Options: 'Flat', 'Islands', 'Steps', 'Custom'\n",
    "\n",
    "Parameters['Feature_Grid'] = 'Square'             # Feature Grid: 'Square', 'Hex': Hexagonal. This is for 'Islands' type only.\n",
    "Parameters['Feature_Layout'] = 'Uniform'          # Feature Layout: 'Uniform': uniform grid, 'Correlated': random offset from uniform , 'Random': random layout\n",
    "Parameters['Feature_Spacing'] = (8,8,0)         # (number in x direction, number in y, avg spread of features (sigma)). For 'Islands' only.\n",
    "\n",
    "Parameters['Size_Distribution'] = 'Gaussian'        # Size ditribution of features: 'None', 'Gaussian', or 'Correlated'\n",
    "Parameters['Size_Values'] = (11,1,0)                # (Avg Radius or Step Length, Height of features, Width of distribution)\n",
    "\n",
    "Parameters['Substrate_Particle_State'] = 'Passive'      # Whether substrate particles are active or not. Options: 'Active', 'Passive'.\n",
    "\n",
    "Parameters['Substrate_File'] = 'Surface_Cov0.6.npy'          # For custom substrate, name of coordinates file. File must be in same directory as simulation script.\n",
    "\n",
    "\n",
    "\n",
    "# Deposition Parameters (Deposition type simulations only)\n",
    "Parameters['Deposition_Type'] = 'PLD'              # Type of deposition simulation. Options: 'PLD' or 'MBE'\n",
    "Parameters['Pulses_per_Layer'] = 20                # number of pulses per monolayer. For PLD only\n",
    "Parameters['Layers'] = 0.05                        # number of monolayers to simulate\n",
    "\n",
    "Parameters['Dwell_Time'] = 10.0                    # Total pulse period (for PLD) or total deposition time (for MBE) in seconds.\n",
    "Parameters['Pulse_Shape'] = 'Uniform'              # Shape of the deposition pulse. Options: 'Uniform', 'Non_Uniform'\n",
    "Parameters['Pulse_Width'] = 1e-8                   # Width of deposition pulse (for PLD) or total deposition time (for MBE, set the same as dwell time) in seconds.\n",
    "\n",
    "Parameters['Post_Anneal'] = False                  # Run a Post Anneal Step (True/False)\n",
    "Parameters['Post_Anneal_Time'] = 100.0             # Length of Post Anneal step in seconds.\n",
    "\n",
    "\n",
    "\n",
    "# Density Map Model Parameters (Density map type simulations only)\n",
    "Parameters['Total_Sims'] = 10                        # total number of sims at each time\n",
    "\n",
    "\n",
    "# Diffusion Only Parameters (Diffusion type simulations only)\n",
    "Parameters['Cluster'] = np.array([[0,1,2],[0,0,0]])                                                 # set up cluster coordinates for surface diffusion\n",
    "Parameters['Cluster'] = np.array([[int(0.5*Parameters['Lx'])],[int(0.5*Parameters['Ly'])]])         # one particle in the middle\n",
    "\n",
    "Parameters['Sim_Time'] = 1.0            # simulation time in seconds\n",
    "\n",
    "\n",
    "\n",
    "# Thermal Processes and Activation Energies (Slow Dynamics)\n",
    "Parameters['Enable_Processes'] = 'No_Uphill'      # Choose which processes to enable. Options: 'All', 'No_Uphill_4NN', 'No_Uphill', 'No_Detach', 'No_Edge'\n",
    "\n",
    "Parameters['w0'] = 10**13                       # Prefactor for Arrhenius law (Crystal Vibration Frequency: w0 ~ kT/h )\n",
    "Parameters['Substrate_Temperature'] = 600       # Substrate temperature in Celcius\n",
    "\n",
    "Parameters['Ea_diffusion'] = 1.8                # Energy Barrier for surface diffusion in eV\n",
    "Parameters['Ea_ehrlich_schwoebel'] = 0.0        # Energy Barrier for downhill/uphill diffusion in eV\n",
    "Parameters['Ea_detach'] = 0.0                   # Energy Barrier for detachment from one nearest neighbor in eV\n",
    "Parameters['Ea_edge'] = 0.0                     # Energy Barrier for Edge diffusion in eV (3D only). Value of 0.0 means same rate as surface diffusion\n",
    "Parameters['Ea_corner'] = 10.0                   # Energy Barrier for Corner diffusion in eV (3D only)\n",
    "\n",
    "\n",
    "\n",
    "# Non-Thermal Processes (Fast Dynamics)\n",
    "Parameters['Downward_Funneling'] = False      # enables downward funneling when particles land on step edges\n",
    "Parameters['Transient_Mobility'] = False      # enables transient mobility\n",
    "Parameters['Island_Chipping'] = False         # enable island chipping"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Analysis Times\n",
    "* Set up non-lienar analysis times"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Reset relevant parmaters\n",
    "Parameters['Analysis_Style'] = 'time'              # choose whether to analyze simulation by time step ('time') or simulation steps ('step')\n",
    "Parameters['Analysis_Time_Spacing'] = 'quad'     # delta t spacing of analysis points. Options: 'linear', 'quad', 'log'. For 'log' this is time of first data point\n",
    "Parameters['Log_Points'] = 200                     # For log spacing option only. This is the number of points per pulse. Set 'Analysis_Delta_Time' to be the first analysis point\n",
    "\n",
    "Parameters['Analysis_Delta_Time'] = 1e-4     # time interval for On-the-Fly analysis in seconds. Set 'Analysis_Style' to 'time'\n",
    "Parameters['Analysis_Delta_Step'] = 1e4      # step interval for On-the-Fly analysis. This will result in non-linear time step for analysis points. Set 'Analysis_Style' to 'step'\n",
    "\n",
    "Parameters['Deposition_Type'] = 'PLD'            # Type of deposition simulation. Options: 'PLD' or 'MBE'\n",
    "Parameters['Pulses_per_Layer'] = 20               # number of pulses per monolayer. For PLD only\n",
    "Parameters['Layers'] = 0.05                         # number of monolayers to simulate\n",
    "\n",
    "Parameters['Dwell_Time'] = 22.0                   # Total pulse period (for PLD) or total simulation time (for MBE) in seconds.\n",
    "Parameters['Pulse_Shape'] = 'Uniform'            # Shape of the deposition pulse. Options: 'Uniform', 'Non_Uniform'\n",
    "Parameters['Pulse_Width'] = 1e-8                 # Width of deposition pulse (for PLD) or total deposition time (for MBE) in seconds. (must be less than dwell time)\n",
    "\n",
    "Parameters['Post_Anneal'] = False               # Run a Post Anneal Step (True/False)\n",
    "Parameters['Post_Anneal_Time'] = 100.0          # Length of Post Anneal step in seconds."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "Parameters['Pulses'] = int(Parameters['Pulses_per_Layer']*Parameters['Layers'])\n",
    "Parameters['Save_File_Name'] = Path.cwd() / 'Test'\n",
    "Analysis = KMC_Analysis.On_the_Fly_Analysis(Parameters,Path.cwd(),np.zeros([Parameters['Lx'],Parameters['Ly'],Parameters['depth']])) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Plot Analysis Times\n",
    "print ('Number of Analysis Points per Pulse = ', int(Analysis.analysis_times.shape[0]/(Parameters['Pulses_per_Layer']*Parameters['Layers'])))\n",
    "plt.figure()\n",
    "plt.plot(np.arange(Analysis.analysis_times.shape[0]),Analysis.analysis_times,'o')\n",
    "plt.ylabel('Time (sec)')\n",
    "plt.xlabel('Points')\n",
    "# plt.yscale('log')\n",
    "plt.tight_layout()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Substrate Generator\n",
    "* Test out substrate features"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Substrate Parameters\n",
    "\n",
    "Parameters['Lx'] = 150           # substrate size in x direction\n",
    "Parameters['Ly'] = 150           # substrate size in y direction (not used in 2D mode)\n",
    "Parameters['depth'] = 10         # how many incomplete layers in the lattice (be careful setting this, or errors could occur)\n",
    "\n",
    "Parameters['Substrate_Type'] = 'Islands'        # Substrate Style . Options: 'Flat', 'Islands', 'Steps', 'Custom'\n",
    "\n",
    "Parameters['Feature_Layout'] = 'Uniform'        # Feature Layout: 'Uniform': uniform grid, 'Correlated': offset from uniform , 'Random': completely random layout \n",
    "Parameters['Feature_Spacing'] = (1,1,0)       # (number in x direction, number in y, avg spread in lattice units)\n",
    "Parameters['Size_Distribution'] = 'None'        # Size ditribution of features: 'None', 'Gaussian', or 'Correlated'\n",
    "Parameters['Size_Values'] = (66,1,0)               # (Avg Radius or Step Length, Height of features, Width of distribution)\n",
    "\n",
    "Parameters['Substrate_Particle_State'] = 'Passive'      # whether substrate particles are active or not. Options: 'Active', 'Passive'.\n",
    "\n",
    "Parameters['Substrate_File'] = 'Surface_Cov0.0999.npy'  # For custom substrate, name of coordinates file. File must be in same directory as simulation script.\n",
    "Parameters['Substrate_File'] = 'Surface_Cov0.1999.npy'\n",
    "Parameters['Substrate_File'] = 'Surface_Cov0.2998.npy'\n",
    "Parameters['Substrate_File'] = 'Surface_Cov0.3998.npy'\n",
    "Parameters['Substrate_File'] = 'Surface_Cov0.4997.npy'\n",
    "# Parameters['Substrate_File'] = 'Surface_Cov0.5997.npy' \n",
    "# Parameters['Substrate_File'] = 'Surface_Cov0.6992.npy'\n",
    "# Parameters['Substrate_File'] = 'Surface_Cov0.7987.npy'\n",
    "# Parameters['Substrate_File'] = 'Surface_Cov0.8964.npy'\n",
    "# Parameters['Substrate_File'] = 'Surface_Cov0.9999.npy'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "Substrate = KMC_Misc.Substrate_Generator(Parameters)\n",
    "List,n = Substrate.Generate_Substrate()\n",
    "Substrate.Plot()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# print (List)\n",
    "print (len(List))\n",
    "print ('Coverage =',len(List)/(Parameters['Lx']*Parameters['Ly']))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# calculate step edge density and internal area\n",
    "surf = Substrate.Surface - 1\n",
    "\n",
    "# plt.figure()\n",
    "# plt.imshow(surf)\n",
    "\n",
    "Lx = surf.shape[0]; Ly = surf.shape[1]\n",
    "Edge = 0\n",
    "Area = 0\n",
    "for i in range(Lx):\n",
    "    for j in range(Ly):\n",
    "        if surf[i,j] > 0:\n",
    "            # count NN\n",
    "            NN = surf[i-1,j] + surf[(i+1)%Lx,j] + surf[i,j-1] + surf[i,(j+1)%Ly]\n",
    "            if NN > 0 and NN < 4:\n",
    "                Edge += 1\n",
    "            elif NN == 4:\n",
    "                Area += 1\n",
    "print (Edge, Area)\n",
    "print (Area/Edge)\n",
    "print (Edge+Area)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "Step_Edge = [2119,3102,3758,4172,4260,4065,3633,2986,1962,711]\n",
    "plt.figure()\n",
    "plt.plot(Step_Edge)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "L = 50\n",
    "length = 10\n",
    "print (int(np.floor(0.5*L/length)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "for key, value in Parameters.items():\n",
    "    print (key, value)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "A = [(1,2,3,4),(5,6,7,8),(9,10,11,12)]\n",
    "B = np.array(A)\n",
    "C = np.append(B,B,axis=0)\n",
    "print (C)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# save a copy of the lattice\n",
    "SaveData = np.copy(Substrate.Surface)\n",
    "SaveName = 'Test_Lattice_20x20_R4_Cor'\n",
    "np.save(SaveName,SaveData)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Evaluate Deposition Parameters"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Update test parameters\n",
    "\n",
    "Parameters['Lx'] = 400            # Substrate size in x direction\n",
    "Parameters['Ly'] = 400            # Substrate size in y direction (not used in 2D mode)\n",
    "\n",
    "# Deposition Parameters (Deposition type simulations only)\n",
    "Parameters['Deposition_Type'] = 'PLD'            # Type of deposition simulation. Options: 'PLD' or 'MBE'\n",
    "Parameters['Pulses_per_Layer'] = 20               # number of pulses per monolayer. For PLD only\n",
    "Parameters['Layers'] = 0.05                        # number of monolayers to simulate\n",
    "\n",
    "Parameters['Dwell_Time'] = 10.0                 # Total pulse period (for PLD) or total simulation time (for MBE) in seconds.\n",
    "Parameters['Pulse_Shape'] = 'Uniform'            # Shape of the deposition pulse. Options: 'Uniform', 'Non_Uniform'\n",
    "Parameters['Pulse_Width'] = 1e-8                 # Width of deposition pulse (for PLD) or total deposition time (for MBE) in seconds. (must be less than dwell time)\n",
    "\n",
    "Parameters['Post_Anneal'] = False               # Run a Post Anneal Step (True/False)\n",
    "Parameters['Post_Anneal_Time'] = 100.0          # Length of Post Anneal step in seconds.\n",
    "\n",
    "n = int(Parameters['Lx']*Parameters['Ly']*Parameters['Layers'])\n",
    "print (n)\n",
    "Parameters['n'] = n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "Deposition = KMC_Dep.Deposition(Parameters)\n",
    "Dep_Times, Dep_Coordinates = Deposition.Create_Deposition_Pulse(time=10.0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print (Dep_Times.shape)\n",
    "print (Dep_Coordinates.shape)\n",
    "print (Dep_Times)\n",
    "print (Dep_Times[3]-Dep_Times[2])\n",
    "print (Dep_Coordinates)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "Avg,Peak = KMC_Misc.Deposition(Parameters).Deposition_Rates()\n",
    "print (Avg,Peak)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Evaluate Energy Barriers and Rates"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Energy Barrier Parameters\n",
    "Parameters['Dimension'] = '3D'  \n",
    "\n",
    "Parameters['w0'] = 10**13  #1.82*10**13        # Prefactor for Arhenius law (Crystal Vibration Frequency: w0 ~ kT/h )\n",
    "Parameters['Substrate_Temperature'] = 850     # Substrate temperature in Celcius\n",
    "\n",
    "Parameters['Ea_diffusion'] = 1.8              # Energy Barrier for surface diffusion in eV\n",
    "Parameters['Ea_ehrlich_schwoebel'] = 0.0      # Energy Barrier for downhill/uphill diffusion in eV\n",
    "Parameters['Ea_detach'] = 0.0                 # Energy Barrier for detachment from one nearest neighbor in eV\n",
    "Parameters['Ea_edge'] = 0.0                   # Energy Barrier for Edge diffusion in eV (3D only). Value of 0 means same as surface diffusion\n",
    "Parameters['Ea_corner'] = 0.0                 # Energy Barrier for Corner diffusion in eV (3D only)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "Rate_Catalog, rates, moves, keys, num_proc = KMC_Proc.Process_Catalog(Parameters).Return_Rates()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "Rate_Catalog"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print (len(rates))\n",
    "print (num_proc)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Plot Rates as function of Ea\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Determine energy barrier to get specific Rate\n",
    "kT = KMC_Misc.Process_Catalog(Parameters).kT\n",
    "k = 5000  # wanted rate\n",
    "Ea = -np.log(k/Parameters['w0'])*kT\n",
    "print (Ea)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "R = 1e6  # D/F ratio\n",
    "\n",
    "avg_dep_rate = Rate_Catalog['Diff']/R   # avg deposition rate setpoint in monolayers/sec\n",
    "print ('Avg Dep Rate =',avg_dep_rate)\n",
    "\n",
    "L = 200    # system size\n",
    "n = L*L    # number of particles in monolayer\n",
    "dep_time = 1/avg_dep_rate\n",
    "print ('Dep Time =',dep_time)\n",
    "\n",
    "print ('0.2 monolayers',0.2*dep_time)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Determine if process can actually happen\n",
    "Rate = Rate_Catalog['Diff_Detach1_ES']\n",
    "Max_Particles = 1000*1000\n",
    "\n",
    "Total_Rate = Rate*Max_Particles\n",
    "print (Total_Rate)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Scaling Law from\n",
    "D = 91\n",
    "k = 1.69\n",
    "r = 3\n",
    "alpha = D/(r*np.log(1/k))\n",
    "print (alpha)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Save Parameters\n",
    "* create a pickle file to load directly into Input_Script"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# print and check that parameters are set correctly\n",
    "Parameters"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
